
Chapter 13.7. Scratchable Java

From the website:

  Killer Game Programming in Java
  http://fivedots.coe.psu.ac.th/~ad/jg

  Dr. Andrew Davison
  Dept. of Computer Engineering
  Prince of Songkla University
  Hat yai, Songkhla 90112, Thailand
  E-mail: ad@fivedots.coe.psu.ac.th


If you use this code, please mention my name, and include a link
to the website.

Thanks,
  Andrew

============================

Scratch
=======
The examples here explain how to link Java and the Scratch programming
language. Scratch can be downloaded from http://scratch.mit.edu

The examples use Scratch's remote sensor connections which were first
added in version 1.3.

============================

Java-Scratch Link
=================
This directory contains four Java classes used by the examples
to support the Java/Scratch connection:

  * ScratchIO.java        // creates the Scratch socket link; contains IO methods

  * ScratchMessage.java   // creates an object representing a Scratch message

  * StringToks.java       // used by ScratchMessage to tokenize Scratch messages
                             (not called by the user directly)

  * MakeSensor.java       // used to create a virtual sensor over in Scratch
                             (only used when a Scratch script needs a virtual sensor)


Compilation:
  > javac *.java


============================

Examples
========
This directory contains five Java/Scratch examples:

1.  UseBroadcasting.java + broadIO.sb
    (demonstrates the use of Scratch broadcast messages)


2.  ReadGlobals.java + varOut.sb
    (demonstrates the use of Scratch global variables)


3.  BroadcastVar.java + broadVar.sb
    (demonstrates the use of virtual sensors, broadcast messages,
     and global variables in Scratch)


4.  TimeResponder.java + MyClock.sb
    (Java acts as an information supplier to Scratch)


5.  TrampolineClient.java, TrampolineWatcher.java + JavaTrampoline.sb
    and the images in the icons/ sub-directory
    (Java controls and updates a Scratch application)


Compilation:
  > javac *.java

----------------------------

Execution of the examples
=========================

1. Before any Java example is started, its Scratch program must
   be loaded into Scratch, and remote sensor connections switched on.
     - go to the "Sensing" blocks collection
     - right click on the "sensor" block
     - select the "enable remote sensor connections" menu item

   This must be done whenever a Scratch program is openned.


2.  Start the Java application:

      > java UseBroadcasting      (after loading broadIO.sb)

    or
      > java ReadGlobals          (after loading varOut.sb _and_ starting it running)

    or
      > java BroadcastVar         (after loading broadVar.sb)

    or
     > java TimeResponder         (after loading MyClock.sb)
     // then start the Scratch code running

    or
     > java TrampolineClient      (after loading JavaTrampoline.sb)
       // press the GUI's buttons to make the girl trampoline


NOTE:
  If you get the message:
               "Scratch IO link could not be created"
  it means that you have not enable remote sensor connections inside
  Scratch.


---------
Last updated: 16th March 2009

